﻿using Microsoft.Xrm.Sdk;

namespace UsersSettingsTool.Additional_Classes.Classes
{
    internal static class Helper
    {
        public static T GetValue<T>(string fieldname, Entity target, Entity image = null)
        {
            if (target != null && target.Contains(fieldname))
            {
                return (T)target[fieldname];
            }

            if (image != null && image.Contains(fieldname))
            {
                return (T)image[fieldname];
            }

            return default(T);
        }

        public static T GetAliasedValue<T>(string fieldname, Entity target, Entity image = null)
        {
            if (target != null && target.Contains(fieldname))
            {
                return (T)target[fieldname];
            }

            if (image != null && image.Contains(fieldname))
            {
                return (T)image[fieldname];
            }

            return default(T);
        }
    }
}
